#ifndef FILESELECTDLG_H
#define FILESELECTDLG_H
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
            TypeName(const TypeName&); \
            void operator=(const TypeName&)

#include <QDialog>
#include <QMessageBox>
#include <QHostAddress>
#include <QtNetwork/QFtp>
#include <QListWidgetItem>
#include <QProgressDialog>
#include <inttypes.h>
#include <QQueue>

#include "ipsetdlg.h"
#include "logindlg.h"
#include "mainwindow.h"
#include "logger.h"
#include "targetuser.h"
#include "projectinfo.h"
#include "bomfileselect.h"

extern QSet<TargetUser> targetUserSet;
extern ProjectInfo targetProject;

namespace Ui {
class fileSelectDlg;
}

class fileSelectDlg : public QDialog
{
    Q_OBJECT

public:
    explicit fileSelectDlg(QWidget *parent = nullptr);
    ~fileSelectDlg();

    void check();
    void connectToServer();

    QString fromFtpEncoding(const QString str);
    QString toFtpEncoding(const QString str);

    void callUpMainwindow(QQueue<QString> multiSelectList, QString BOMFile);
    void showList(QStringList videoList, int start);
    void setHostAndPort(QString hostAddr ,unsigned short port);
//    void setUserNum(QString id);
//    void setUsername(QString name);
    bool checkMultiSelect();
    void downloadVideoAndBOM();
//    bool modifyDb();

public slots:
    void getVideoList(const QUrlInfo &i);

    void keyPressEvent(QKeyEvent *event);

    void closeEvent(QCloseEvent *event);

    void updateDataTransferProgress(qint64 readBytes,
                                    qint64 totalBytes);
//    void setIPAndPort(QString hostAddr, unsigned short port);

private slots:
    void on_okBtn_clicked();

    void ftpCommandFinished(int, bool error);

    void on_upBtn_clicked();

    void on_cancelBtn_clicked();

    void on_prevBtn_clicked();

    void on_nextBtn_clicked();

    void on_addBtn_clicked();

    void on_rmvBtn_clicked();

    void on_downloadListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);

    void processCheckFile();

    void on_listWidget_itemDoubleClicked(QListWidgetItem *item);

    void on_listWidget_itemClicked(QListWidgetItem *item);

    void cancelDownload();

//    void on_IpChangeBtn_clicked();

private:
    DISALLOW_COPY_AND_ASSIGN(fileSelectDlg);
    Ui::fileSelectDlg *ui;

    QString hostAddr;
    unsigned short port;
    QFtp *ftp;

    QStringList videoList;
    QQueue<QString> selectQueue;
    QQueue<QString> playQueue;
    QHash<QString, bool> isDir;
    QString BOMFile;
    QString fileName;
    QString currentPath = "/";
    QString userId;
//    QString userName = "null";
    QFile *file = new QFile(this);
    QProgressDialog *downloadProgressDlg;
    bool canQuit = false;

//    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    QSqlDatabase db = QSqlDatabase::database();

    Logger logger;

    bool hasBomFlag = false;
    
signals:
    void checkFile();
};

#endif // FILESELECTDLG_H
